﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Pheonix.CodeLibrary.Web;
using Pheonix.Fashionzoomer.DAL;
using Pheonix.CodeLibrary;
using Pheonix.Fashionzoomer.BLL;

public partial class private_ChangePassword : PrivateBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Title = SiteName + " - Change Password";
        ibtSave.ImageUrl = "~/App_Themes/" + Page.StyleSheetTheme + "/image/edit.gif";
        ibtCancel.ImageUrl = "~/App_Themes/" + Page.StyleSheetTheme + "/image/edit.gif";
    }

    protected void Save_Click(object sender, ImageClickEventArgs e)
    {
        if (Page.IsValid)
        {
            int userId = SessionManager.LoggedUser.Id;
            string userOldPassword = Utility.FilterInputText(tbxOldPassword.Text);
            string userNewPassword = Utility.FilterInputText(tbxNewPassword.Text);

            if (CustomCommand.CheckOldPassword(userId, userOldPassword))
            {
                if (UserManager.SetNewPassword(userId, userNewPassword))
                    uccResponseMessage.SetSuccessMessage("Password Changed");
                else
                    uccResponseMessage.SetFailMessage("Failed to change password.");
            }
            else
                uccResponseMessage.SetFailMessage("Failed to change password");
        }
        else
            uccResponseMessage.SetFailMessage("Sorry we could not update your information");
        
    }

    protected void Cancel_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("MyAccount.aspx");
    }
}
